package com.chapter13.MyCollection.MyMap.MyHashMap;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class UseHashMap {
    public static void main(String[] args) {
        Map<Integer, String> map = new HashMap<Integer, String>();
        map.put(1,"one");
        map.put(2,"two");
        map.put(3,"three");
        //所有的key
        Set<Integer> keys = map.keySet();
        for (Integer key:keys){
            System.out.println(key);
        }
        //所有的value
        Collection<String> values = map.values();
        for (String value:values){
            System.out.println(value);
        }
        //所有的键值对
        Set<Map.Entry<Integer, String>> entries = map.entrySet();
        for (Map.Entry entry:entries){
            System.out.println(entry.getKey()+","+entry.getValue());
        }

        //遍历键值对
        map.forEach((key,value)-> System.out.printf("%d:%s\t",key,value));
    }
}
